package cn.zero.controller;

import cn.zero.domain.Product;
import cn.zero.domain.Result;
import cn.zero.service.IProductServer;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductServer productServer;

    @PostMapping("/save")
    @HystrixCommand(fallbackMethod = "fallbackMethod")
    public Result save(@RequestBody Product product) {
        try {
            productServer.save(product);
            return new Result(false,"操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"操作失败");

        }
    }

    public Result fallbackMethod(@RequestBody Product product){
        return new Result(false,"接口失败");
    }

}
